package com.shuoyue.ycgk.ui.recruitment.job;


import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.JobInfo;
import com.shuoyue.ycgk.utils.MyImageSpan;

import java.util.List;

public class JobAdapter extends AppBaseQuickAdapter<JobInfo> {
    boolean isShowDelete = false;

    public JobAdapter(@Nullable List<JobInfo> data, boolean isShowDelete) {
        super(R.layout.item_job, data);
        this.isShowDelete = isShowDelete;
    }

    public JobAdapter(@Nullable List<JobInfo> data) {
        this(data, false);
    }

    @Override
    protected void convert(BaseViewHolder helper, JobInfo item) {
        helper.addOnClickListener(R.id.lay_all);
        helper.addOnClickListener(R.id.delete);

        helper.setText(R.id.jobName, item.getPostName());
        helper.setText(R.id.subtitle1, Html.fromHtml("招聘单位:<font color='#333333'>" + item.getPostUnit()));
        helper.setText(R.id.subtitle2, Html.fromHtml("来自公告:<font color='#333333'>" + item.getTitle()));
        helper.setGone(R.id.delete, isShowDelete);

        helper.setText(R.id.info2, item.getAreaName() + " . " + item.getModuleName());
//        helper.setText(R.id.info3, "招聘" + item.getPersonNum() + "人");
        helper.setText(R.id.info3, Html.fromHtml("招聘<font color='#2196F3'>" + item.getPersonNum() + "</font>人"));//招10人/15个职位

        if (item.getStatus() == 1) {
            helper.setText(R.id.status, "即将报名");
            helper.setBackgroundRes(R.id.status, R.mipmap.job_status_blue);
        } else if (item.getStatus() == 0) {
            helper.setText(R.id.status, "正在报名");
            helper.setBackgroundRes(R.id.status, R.mipmap.job_status_orange);
        } else {
            helper.setText(R.id.status, "报名结束");
            helper.setBackgroundRes(R.id.status, R.mipmap.job_status_gray);

        }

    }


    private void setTextSpandable(String text, TextView textView) {
        //创建SpannableString对象
        SpannableString string = new SpannableString(text + "  ");
        int len = string.length();
        //创建ImageSpan对象
        Drawable rightDrawable = mContext.getResources().getDrawable(R.mipmap.icon_hot);
        rightDrawable.setBounds(0, 0, 35, 35);
        MyImageSpan imageSpan = new MyImageSpan(rightDrawable);
        //给SpannableString对象设置ImageSpan
        string.setSpan(imageSpan, len - 1, len, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        textView.setText(string);
    }
}
